package com.gitee.wsl.mathematics.coordinate.polar.ext

import com.gitee.wsl.mathematics.vector.ext.cosine
import com.gitee.wsl.mathematics.vector.ext.sine
import com.gitee.wsl.mathematics.vector.vec2.Vec2
import com.gitee.wsl.mathematics.vector.vec2.Vec2f
import com.gitee.wsl.mathematics.vector.vec2.Vector2
import com.gitee.wsl.unit.angle.AngleUnit

/** Constructs a point from polar coordinates determined by an [angle] and a [length]. Angle 0 is pointing to the right, and the direction is counter-clock-wise for up=UP and clock-wise for up=UP_SCREEN */
inline fun polar(x: Float, y: Float, angle: AngleUnit, length: Float = 1f, up: Vec2 = Vec2.up) = Vec2f(x + angle.cosine(up) * length, y + angle.sine(up) * length)
inline fun polar(x: Double, y: Double, angle: AngleUnit, length: Float = 1f, up: Vec2 = Vec2.up) = Vec2f(x + angle.cosine(up) * length, y + angle.sine(up) * length)
inline fun polar(base: Vector2<*, *>, angle: AngleUnit, length: Float = 1f, up: Vec2 = Vec2.up) = polar(base.x.toDouble(), base.y.toDouble(), angle, length, up)
inline fun polar(angle: AngleUnit, length: Float = 1f, up: Vec2 = Vec2.up) = polar(0.0, 0.0, angle, length, up)
